<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */

defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['setting']=$this->plugin_setting('basic');
$uniacid=$_SESSION['uniacid'];
if($_RQ['op']=='main'){
	//查询评价
	$id=$_RQ['id'];
	$list=pdo_getall('jy_tour_assess',array('uniacid'=>$uniacid,'status'=>1,'way_id'=>$id));
	$return['list']=$list;
	$return['params']=array('keyword'=>'');
	$fuwu=pdo_getall('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','way_id'=>$id));
	$star5=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'5','way_id'=>$id));
	$star4=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'4','way_id'=>$id));
	$star3=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'3','way_id'=>$id));
	$star2=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'2','way_id'=>$id));
	$star1=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'1','way_id'=>$id));
	$fuwu_count=count($fuwu);
	if($fuwu_count>0){
		$fuwu['star5']=$star5/$fuwu_count*100;
		$fuwu['star4']=$star4/$fuwu_count*100;
		$fuwu['star3']=$star3/$fuwu_count*100;
		$fuwu['star2']=$star2/$fuwu_count*100;
		$fuwu['star1']=$star1/$fuwu_count*100;
	}else{
		$fuwu['star5']=$fuwu['star4']=$fuwu['star3']=$fuwu['star2']=$fuwu['star1']=0;
	}
	//评价平均分
	$sql = "SELECT SUM(star) FROM " . tablename('jy_tour_assess') . " WHERE uniacid=:uniacid AND way_id=:way_id AND status=1";
	$sum = pdo_fetch($sql,array(":uniacid" => $_SESSION['uniacid'],"way_id"=>$id));	
	$star_sum = $sum['SUM(star)'];
	$star_fen=number_format($star_sum/$fuwu_count,1)?number_format($star_sum/$fuwu_count,1):4.6;
	$return['fuwu']=$fuwu;
	$return['post']=array('star'=>$month_assess['star']);
	$return['month']=date('m');
	$return['month_assess']=$month_assess;
	$return['star_fen']=$star_fen;
	$return['fuwu_count']=$fuwu_count;
	exi($return);
}
if($_RQ['op']=='getlist'){
	if(!empty($_RQ['keyword'])){
		$params['name like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=$_RQ['keyword'];
	}
	$params['status']=1;
	$params['uniacid']=$uniacid;
	$params['way_id']=$_RQ['way_id'];
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','way_id','order_id','merchid','star','mid','content','reply','status','createtime');
	$list=pdo_getslice('jy_tour_assess',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$row){
			
			$way=pdo_get('jy_tour_way',array('id'=>$row['way_id']));
			$row['member']=pdo_get('core_members',array('id'=>$row['mid']));
			$row['merchid']=pdo_get('jy_tour_merch',array('id'=>$row['merchid']));
			$row['way']=$way;
			$row['createtime']=date('Y-m-d',$row['createtime']);
		}
	}
	
	$return['list']=$list;
	exi($return);
	
}

if($_RQ['op']=='pingjia'){
	$order_id=$_RQ['id'];
	if(!$order_id){
		exi('未找到订单！','error');
	}
	$order=pdo_get('jy_tour_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order_id));
	$way=pdo_get('jy_tour_way',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['way_id']));
	$pingjianum=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'way_id'=>$way['id']));
	$pinjia_good=pdo_count('jy_tour_assess',array('uniacid'=>$_SESSION['uniacid'],'way_id'=>$way['id'],'star >'=>'3'));
	$way['manyidu']=number_format($pinjia_good/$pingjianum,0);
	$way['pingjianum']=$pingjianum;
	$return['way']=$way;
	$return['post']=array('way_id'=>$way_id,'order_id'=>$order_id,'merchid'=>$order['merchid']);
	exi($return);
}
		
if($_RQ['op']=='submit'){
	$post=get_postdata();
	//print_r($post);exit;
	$insert=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'merchid'=>$post['merchid'],
		'way_id'=>$post['way_id'],
		'order_id'=>$post['order_id'],
		'content'=>$post['content'],
		'label'=>$post['label'],
		'star'=>$post['star'],
		'status'=>1,
		'createtime'=>TIMESTAMP,
	);
	pdo_insert('jy_tour_assess',$insert);
	//评价成功,修改订单状态
	pdo_update('jy_tour_order',array('status'=>3),array('id'=>$post['order_id']));
	exi('评价成功!','','jy_tour/way.assess_detail/main/id='.$post['way_id']);
}		


